var TableDatatablesAjax = function() {
  var datatableAjax = function(){
    dt = $('#datatable_ajax');
    ajax_datatable = dt.DataTable({
      "processing": true,
      "serverSide": true,
      "searching" : false,
     
      "ajax": {
        'url' : '/admin/amiba/ajaxCount',
        "data": function ( d ) {
          d.bar = $('.filter select[name="bar"] option:selected').val();
           d.daozhen = $('.filter input[name="daozhen"]').val();
           d.yuji_shouru = $('.filter input[name="yuji_shouru"]').val();
          d.lirun = $('.filter input[name="lirun"]').val();
          d.time = $('.filter input[name="time"]').val();
          d.created_at_from = $('.filter input[name="created_at_from"]').val();
          d.wincomebutton = $('.filter input[name="wincomebutton"]').val();
        }
      },
      "pagingType": "bootstrap_full_number",
      "order" : [],
      "orderCellsTop": true,
      "dom" : "<'row'<'col-sm-3'l><'col-sm-6'<'customtoolbar'>><'col-sm-3'f>>" +"<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-5'i><'col-sm-7'p>>",
      "columns": [
        {
          "data": "id",
          "name" : "id",
        },
        {
          "data": "bar",
          "name" : "bar",
          "orderable" : true,
          render:function(data){
           if (data == 1) {
              return '<span class="label label-success">网络巴 </span>';
            }else if(data == 2){
              return '<span class="label label-warning" style="background-color:red">  渠道巴 </span>';
            }else if(data == 3){
              return '<span class="label label-warning" style="background-color:blue">  电商巴 </span>';
            }else if(data==4){
              return '<span class="label label-warning" style="background-color:green">  自媒体巴 </span>';
            }else if(data==5){
                return '<span class="label label-warning" style="background-color:#EA6D00">  企划巴 </span>';  
            }else if(data==6){
               return '<span class="label label-warning" style="background-color:#E438B0">  设计巴 </span>';  
            }else if(data==7){
               return '<span class="label label-warning" style="background-color:#58CB5B"#>  技术巴 </span>';  
            }else if(data==8){
               return '<span class="label label-warning">  咨询巴 </span>';  
            }else if(data==9){
               return '<span class="label label-warning">  搜牙巴 </span>';  
            }
          }
          
        },
       
        { 
          "data": "daozhen",
          "name": "daozhen",
          "orderable" : false,
        },
        { 
          "data": "yuji_shouru",
          "name": "yuji_shouru",
          "orderable" : true,
          
        },
        { 
          "data": "lirun",
          "name": "lirun",
          "orderable" : true,
        },

         { 
          "data": "time",
          "name": "time",
          "orderable" : true,
          
        },
        
   
        
         {
          "data": "wincomebutton",
           "name": "wincomebutton",
           "type": "html",
           "orderable": false,
         },
        
      ],
      "drawCallback": function( settings ) {
        ajax_datatable.$('.tooltips').tooltip( {
          placement : 'top',
          html : true
        });  
      },
      "language": {
        url: '/admin/i18n'
      }
    });

    dt.on('click', '.filter-submit', function(){
      ajax_datatable.ajax.reload(); 
    });

    dt.on('click', '.filter-cancel', function(){
      $('textarea.form-filter, select.form-filter, input.form-filter', dt).each(function() {
          $(this).val("");
      });

      $('select.form-filter').selectpicker('refresh');

      $('input.form-filter[type="checkbox"]', dt).each(function() {
          $(this).attr("checked", false);
      });
      ajax_datatable.ajax.reload();
    });

    $('.input-group.date').datepicker({
      autoclose: true
    });
    $(".bs-select").selectpicker({
      iconBase: "fa",
      tickIcon: "fa-check"
    });
  };

  return {
    init : datatableAjax
  }
}();